package cn.com.oyat.idea.config;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import cn.com.oyat.idea.util.SnowFlakeUtil;
import org.springframework.stereotype.Component;

/**
 * @Classname CustomIdGenerator
 * @Date 2023/5/22 15:44
 * @Created by 87766867@qq.com
 */
@Component
public class CustomIdGenerator implements IdentifierGenerator {
    @Override
    public Long nextId(Object entity) {
        //可以将当前传入的class全类名来作为bizKey,或者提取参数来生成bizKey进行分布式Id调用生成.
        String bizKey = entity.getClass().getName();
        //根据bizKey调用分布式ID生成
        long id = SnowFlakeUtil.getId();
        //返回生成的id值即可.
        return id;
    }

    @Override
    public String nextUUID(Object entity) {
        return SnowFlakeUtil.getIdOfStr();
    }
}
